package com.sigmatrix.h5.service.db;

import java.util.List;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.sigmatrix.h5.config.TableUtils;
import com.sigmatrix.h5.entity.v2.CodeInspectionRecord;
import com.sigmatrix.h5.enums.CodeInspectFinalStatus;
import com.sigmatrix.h5.enums.CodeInspectStatus;
import com.sigmatrix.h5.mapper.CodeInspectionRecordMapper;
import com.sigmatrix.h5.service.v2.CommonDBService;


@Service
public class CodeInspectionRecordDBService extends CommonDBService<CodeInspectionRecordMapper, CodeInspectionRecord> {


	/**
	 * 通过userId查询检查正常记录
	 * 
	 * @param eseCode
	 * @param acctId
	 * @return
	 */
	public List<CodeInspectionRecord> findOKByUserId(String eseCode, Integer acctId) {
		CodeInspectionRecord record = new CodeInspectionRecord();
		record.setUserId(acctId);
		record.setFinalStatus(CodeInspectFinalStatus.NO_FLEE.value);
		record.setTablePrefix(TableUtils.tablePrefixBy(eseCode));
		return selectList(new EntityWrapper<CodeInspectionRecord>(record));
	}
	
	/**
	 * 通过userId查询串货记录
	 * 
	 * @param eseCode
	 * @param acctId
	 * @return
	 */
	public List<CodeInspectionRecord> findNGByUserId(String eseCode, Integer acctId) {
		CodeInspectionRecord record = new CodeInspectionRecord();
		record.setUserId(acctId);
		record.setFinalStatus(CodeInspectFinalStatus.FLEE.value);
		record.setTablePrefix(TableUtils.tablePrefixBy(eseCode));
		return selectList(new EntityWrapper<CodeInspectionRecord>(record));
	}

	/**
	 * 
	 * @param record
	 * @return
	 */
	public CodeInspectionRecord insertAndReturn(CodeInspectionRecord record) {
		Integer id = baseMapper.insertAndReturnId(record);
		record.setId(id);
		return record;
	}

}
